<?php
class InvestProgramPage extends MemberPage {
	private static $singular_name = "Invest Program Page";
    private static $plural_name = "Invest Program Pages";
    private static $default_parent = 'CommissionPage';

    private static $db = array();

    private static $has_one = array();

}

class InvestProgramPage_Controller extends MemberPage_Controller {

    /**
     * An array of actions that can be accessed via a request. Each array element
     * should be an action name, and the
     * permissions or conditions required to allow the user to access it.
     *
     * <code>
     * array (
     *     'action', // anyone can access this action
     *     'action' => true, // same as above
     *     'action' => 'ADMIN', // you must have ADMIN permissions to access this
     * action
     *     'action' => '->checkAction' // you can only access this action if
     * $this->checkAction() returns true
     * );
     * </code>
     *
     * @var array
     */
    private static $allowed_actions = array(
        'Form',
        'view'
    );

    public function init() {
        parent::init();
    }

    function Form() {
        $fields = FieldList::create(
            DateRangeField::create('Created', _t('InvestProgramPage.INVEST_DATE', 'Invest Date'))
        );

        $field_list = array(
            'Created' => _t('InvestProgramPage.INVEST_DATE', 'Invest Date'),
            'Group.TitleByLang' => _t('InvestProgramPage.TYPE', 'Type'),
            'InvestAmount' => array('title' => _t('InvestProgramPage.INVEST_AMOUNT', 'Invest Amount ({currency})', '', array('currency' => SiteCurrencyConfig::current_site_currency())), 'classes' => 'text-right'),
            'Percentage' => array('title' => _t('InvestProgramPage.PERCENTAGE', 'Percentage'), 'classes' => 'text-right'),
            'TotalPayoutWithLink' => array('title' => _t('InvestProgramPage.TOTAL_PAYOUT', 'Total Payout ({currency})', '', array('currency' => SiteCurrencyConfig::current_site_currency())), 'classes' => 'text-right'),
            'PaidDay' => array('title' => _t('InvestProgramPage.PAID_DAY', 'Paid Day'), 'classes' => 'text-center'),
            'IsClosed' => array('title' => _t('InvestProgramPage.IS_CLOSED', 'Is Closed?'), 'classes' => 'text-center')
        );
        $casting_list = array(
            'Created' => 'SS_Datetime->Nice',
            'InvestAmount' => 'Double->Nice',
            'Percentage' => 'Percentage->Nice',
            'PaidDay' => 'Int->Formatted',
            'IsClosed' => 'Boolean->Nice'
        );

        return DataListSearchForm::create($this, 'Form', 'InvestProgram', array('MemberID' => $this->CurrentMember()->ID), $fields)->setDataFieldList($field_list)->setFieldCasting($casting_list);
    }

	function view() {
        $fields = FieldList::create();
		$actions = FieldList::create();

        $field_list = array(
            'Created' => _t('InvestProgramPage.PAYOUT_DATE', 'Payout Date'),
            'Description' => _t('InvestProgramPage.BONUS_DESCRIPTION', 'Description'),
            'AmountText' => array('title' => _t('InvestProgramPage.AMOUNT', 'Amount ({currency})', '', array('currency' => SiteCurrencyConfig::current_site_currency())), 'classes' => 'text-right'),
            'ForwardBalance' => array('title' => _t('InvestProgramPage.BALANCE', 'Balance ({currency})', '', array('currency' => SiteCurrencyConfig::current_site_currency())), 'classes' => 'text-right')
        );
        $casting_list = array(
            'Created' => 'SS_Datetime->Nice',
            'ForwardBalance' => 'Double->Nice'
        );

        return DataListSearchForm::create($this, 'view', 'InvestProgramPayout', array('InvestProgram.MemberID' => $this->CurrentMember()->ID, 'InvestProgramID' => $this->request->param('ID')), $fields, $actions)->setDataFieldList($field_list)->setFieldCasting($casting_list)->forTemplate();
    }
}
